#!/bin/bash
# Name:bakmysql.sh
# This is a ShellScript For Auto DB Backup and Delete old Backup
#
backupdir=/data/mysql/mysqlbak
time=` date +%Y%m%d `
/usr/local/services/mysql/bin/mysqldump -uroot -p123456 xx_s0 | gzip > $backupdir/xx_$time.sql.gz
/usr/local/services/mysql/bin/mysqldump -uroot -p123456 mzdev | gzip > $backupdir/mz_$time.sql.gz
#
find $backupdir -name "xx_*.sql.gz" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1
find $backupdir -name "mz_*.sql.gz" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1

cp $backupdir/../var/sql.log $backupdir/sql_$time.log
echo "" > $backupdir/../var/sql.log
find $backupdir -name "sql_*.log" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1
